package com.noble.glamour.ui.agora.view;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.noble.library.image.ImageLoader;
import com.noble.library.view.roadlights.LMarqueeFactory;
import com.noble.glamour.R;
import com.noble.glamour.bean.my.GiftsList;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.glamour.ui.agora.act.bean.RtcGiftList;

/**
 * 音视频跑马灯布局
 * Created by Su on 2017/7/18.
 */
public class RtcGiftInfoView extends LMarqueeFactory<LinearLayout, RtcGiftList.GiftInfo> {

    private Context mContext;
    private GiftsList giftsList;  // 在线配置礼物列表

    public RtcGiftInfoView(Context mContext) {
        super(mContext);
        this.mContext = mContext;
        giftsList = ModuleMgr.getCommonMgr().getGiftLists();
    }

    @Override
    public LinearLayout generateMarqueeItemView(RtcGiftList.GiftInfo data) {
        LinearLayout linearLayout = (LinearLayout) inflate(R.layout.f1_chat_gift_info_view);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearLayout.setLayoutParams(params);

        TextView tvFromName = (TextView) linearLayout.findViewById(R.id.tv_from_name);
        TextView tvToName = (TextView) linearLayout.findViewById(R.id.tv_to_name);
        TextView tvGiftName = (TextView) linearLayout.findViewById(R.id.tv_gift_name);
        ImageView ivGiftImg = (ImageView) linearLayout.findViewById(R.id.iv_gift_img);
        TextView tvGiftCount = (TextView) linearLayout.findViewById(R.id.tv_gift_count);

        if (giftsList != null) {
            tvFromName.setText(data.getFrom_name());
            tvToName.setText(data.getTo_name());
            tvGiftCount.setText("x" + data.getCount());
            GiftsList.GiftInfo giftInfo = giftsList.getGiftInfo(data.getGift_id());
            if (giftInfo != null) {
                tvGiftName.setText(giftInfo.getName());
                ImageLoader.loadCenterCrop(mContext, giftInfo.getPic(), ivGiftImg);
            }
        }
        return linearLayout;
    }
}
